<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/4/8
 * Time: 11:22
 */

namespace common\logics\pepperrecord;

use Yii;
use common\widgets\Tool;
use yii\base\BaseObject;

class PepperRecordLogic extends BaseObject implements IPepperRecord
{
    /** @var \common\sources\read\pepperrecord\PepperRecordAccess $RPepperRecordAccess ***/
    private $RPepperRecordAccess;

    public function init()
    {
        $this->RPepperRecordAccess = Yii::$container->get("RPepperRecordAccess");
        parent::init(); // TODO: Change the autogenerated stub
    }

    public function getPepperList($data)
    {
        if(empty($data['buy_id']))
        {
           return Tool::returnJson([],401,"买手id不能为空");
        }
        if(empty($data['safetyCode']))
        {
            return Tool::returnJson([],402,"安全码不能为空");
        }
        if(md5($data['buy_id']) != $data['safetyCode'])
        {
            return Tool::returnJson([],403,"安全码不正确");
        }
        $count = $this->RPepperRecordAccess->getCount($data);
        $list = [];
        if($count >0)
        {
            $list = $this->RPepperRecordAccess->getList($data);
        }
        return Tool::returnJson([
            "list" => $list,
            "count" => $count,
            "page_num" => $data['page_num']
        ],200,"成功");
    }
}